package com.etasist;

/*
 * @auther: issa rabbba
 * @date: 2007-04-18
 * 
 */

import java.io.*;
import java.util.ArrayList;
import java.util.Properties;
import java.util.Enumeration;

public class ConfigInfo {
	
	public static String allCommands = "deny";
	public static int serverPort=4444;
	public static ArrayList allowedCommands = new ArrayList();

	public ConfigInfo(String fileName) {
		Properties properties = new Properties();
	    try {
	        properties.load(new FileInputStream(fileName));
	        
	        if (properties.getProperty("allCommands") != null )
	        	allCommands = properties.getProperty("allCommands", "deny");
	        System.out.println("Allow all commands: "+allCommands);
	        
	        if (properties.getProperty("serverPort") != null )
	        	serverPort =Integer.parseInt(properties.getProperty("serverPort", "4444"));
	        
	        System.out.println("Server port: "+serverPort);
	        
	        getAllowedCommands(properties);
	        
	    } catch (IOException e) {
	    	System.out.println("ERROR: in read the properties file.");
	    	e.printStackTrace();
	    }
	    
	}
	
	static void getAllowedCommands(Properties prop){
		try{
			Enumeration en = prop.propertyNames();
			while (en.hasMoreElements()){
				String s = en.nextElement().toString();
				if (s.indexOf("command.allow.")>-1){
					System.out.println("add <"+prop.get(s)+"> to allowed commands");
					allowedCommands.add(prop.get(s));
				}
			}
				
		}catch (Exception e) {
			System.out.println("ERROR: in read allowed commands.");
			e.printStackTrace();
		}
	}

}
